<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">意见反馈</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>意见反馈</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="suggest-search-option">
            </select>&emsp;
            <input id="suggest-edit-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="suggest-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <!-- 数据表格 -->
        <table class="layui-table" id="suggest-table" lay-filter="suggest-table"></table>
    </div>
</div>

<!-- 表单弹窗 -->
<script type="text/html" id="suggest-model">
    <form id="suggest-form" lay-filter="suggest-form" class="layui-form model-form">
        <input name="sugeid" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">建议群体</label>
            <div class="layui-input-block">
                <input name="sugperStr" type="text" class="layui-input" readonly/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">建议对象</label>
            <div class="layui-input-block">
                <input name="nickName" type="text" class="layui-input" readonly/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">建议内容</label>
            <div class="layui-input-block">
                <div class="layui-textarea" id="suggestion" readonly></div>
            </div>
        </div>
        <div class="layui-form-item model-form-footer">
            <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        </div>
    </form>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="suggest-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="show">查看</a>
</script>

<script>
    layui.use(['form', 'table', 'config', 'admin'], function () {
        let form = layui.form;
        let table = layui.table;
        let config = layui.config;
        let layer = layui.layer;
        let admin = layui.admin;

        getRole();

        let url = config.base_server + 'api-paper/suggest/getSuggestions';
        let params = {
            access_token: config.getToken().access_token
        };

        let cols = [[
            {type: 'numbers'},
            {field: 'username', sort: true, title: '发布者'},
            {field: 'contex', sort: true, title: '建议内容'},
            {field: 'sugperStr', sort: true, title: '建议群体'},
            {field: 'nickName', sort: true, title: '建议对象'},
            {field: 'cretim', sort: true, title: '发布时间'},
            {align: 'center', toolbar: '#suggest-table-bar', title: '操作', width: 80}
        ]];
        //渲染表格
        table.render({
            elem: '#suggest-table',
            url: url,
            where: params,
            page: true,
            cols: cols,
            done: function (res) {
                console.log(res);
            }
        });

        // 工具条点击事件
        table.on('tool(suggest-table)', function (obj) {
            let data = obj.data;
            if (obj.event === 'show') {
                showModel(data);
            }
        });

        // 搜索按钮点击事件
        $('#suggest-btn-search').click(function () {
            let key = $('#suggest-search-option').val();
            let value = $('#suggest-edit-value').val();
            table.reload('suggest-table', {where: {searchKey: key, searchValue: value}});
        });

        // 显示弹窗
        let showModel = function (data) {
            layer.open({
                type: 1,
                title: '意见详情',
                content: $('#suggest-model').html(),
                area: '600px',
                offset: '100px',
                success: function () {
                    $('#suggestion').html(data.contex);
                    form.val('suggest-form', data);
                }
            });
        };

        /**
         * 获取角色
         */
        function getRole() {
            admin.req('api-user/roles', {}, function (result) {
                let data = result.data;
                let html = '<option value="">-请选择-</option>';
                for (let i = 0; i < data.length; i++) {
                    html += '<option value="' + data[i].id + '">' + data[i].name + '</option>'
                }
                $('#suggest-search-option').html(html);
            }, 'GET');
            form.render();
        }
    });

</script>